#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>

#define maxSize 3

using namespace std;

// 二维数组 m * n 矩阵，找出即是行又是列上的最小值，统计个数、坐标、和数值
void printmin(int A[][maxSize], int m, int n)
{
    int i, j, k, min, minj;
    int flag;
    for (i = 0; i < m; ++i)
    {
        min = A[i][0];
        minj = 0;
        // 查找该行上的最小值
        for (j = 1; j < n; ++j)
        {
            if (A[i][j] < min)
            {
                min = A[i][j];
                minj = j;
            }
        }
        // 验证min是不是该列上的最小值
        flag = 1;
        for (k = 0; k < m; ++k)
        {
            if (min > A[k][minj])
            {
                // 不是最小值
                flag = 0;
                break;
            }
        }
        if (flag)
        {
            std::cout << "minValue: " << min << ",position: [" << (i + 1) << "," << (minj + 1) << "]";
        }
    }
}

int main()
{
    int A[3][3] = {{3, 1, 2}, {6, -1, 5}, {8, 7, 9}};
    printmin(A, 3, 3);

    return 0;
}